package com.wm.web.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.interceptor.SessionAware;

import com.wm.bean.Area;
import com.wm.bean.City;
import com.wm.bean.Orders;
import com.wm.comm.Constant;
import com.wm.service.AreaService;
import com.wm.service.CityService;
import com.wm.service.OrdersService;
import com.wm.service.web.PageList;
import com.wm.service.web.Pages;
import com.wm.web.ui.OptionsInt;
import com.wm.web.ui.OptionsLong;

public class AdminOrders extends BaseAction{
	private static final Log logger = LogFactory.getLog(AdminOrders.class);
	
	private OrdersService ordersService;

	public OrdersService getOrdersService() {
		return ordersService;
	}

	public void setOrdersService(OrdersService ordersService) {
		this.ordersService = ordersService;
	}
	
	private List stateList = new ArrayList();

	public List getStateList() {
		return stateList;
	}

	public void setStateList(List stateList) {
		this.stateList = stateList;
	}
	
	private void setStateListValues(){
		stateList.add(new OptionsInt(-1, "请选择"));
		stateList.add(new OptionsInt(0, "下单"));
		stateList.add(new OptionsInt(1, "饭店接单"));
		stateList.add(new OptionsInt(2, "送出"));
		stateList.add(new OptionsInt(3, "交易成功"));
	}
	
	private void initValues(){
		setStateListValues();
	}
	
	private void listInitValues(){
		setStateListValues();
	}

	private long id;			//主键ID
	private int state = -1;		//状态，0下单1饭店接单2送出3交易成功,状态不为0用户不可删除			

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}
	
	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
	}	

	private PageList pageList;
	private Orders orders;
	
	public PageList getPageList() {
		return pageList;
	}

	public void setPageList(PageList pageList) {
		this.pageList = pageList;
	}

	public Orders getOrders() {
		return orders;
	}

	public void setOrders(Orders orders) {
		this.orders = orders;
	}

	public String execute() {
		try {
			return this.executeMethod(this.getAction());
		} catch (Exception e) {
			logger.error(e);
			return INPUT;
		}
	}

	/**
	 * 初始页
	 */
	public String index(){
		listInitValues();
		Pages pages = new Pages();
		pages.setPage(this.getPage());
		pages.setPerPageNum(Constant.PAGE_NUM);
		if (this.getTotal() > 0) {
			pages.setTotalNum(this.getTotal());
		}
		pages.setFileName("/admin_orders.action?state=" + this.state);
		this.setPageList(this.getOrdersService().findOrdersByState(this.state,"id", 1, pages));
		return SUCCESS;
	}
	
	public String show(){
		this.setOrders(this.getOrdersService().findOrdersByid(this.id));
		return "show";
	}


}
